{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%reload_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "import sys\n",
    "sys.path.append(os.path.abspath('../'))\n",
    "from common import *\n",
    "import configs\n",
    "import matplotlib.patches as patches\n",
    "\n",
    "fig_name = 'limitations'\n",
    "fig_dir = join(FIGURE_DIR, fig_name)\n",
    "\n",
    "scenes = ['lego']\n",
    "crops = [(300,200,100,100)]\n",
    "crops = [(0.17,0.85,0.2,0.7)]\n",
    "# crops = [(1,1,1,1)]\n",
    "insets = [[(0.33, 0.5, 0.15), (0.6, 0.44, 0.15)]]\n",
    "exposures = [1.0]\n",
    "config = configs.Warp()\n",
    "\n",
    "fontsize = 12\n",
    "base_size = 4\n",
    "n_rows = len(scenes) \n",
    "n_cols = 3\n",
    "total_width = COLUMN_WIDTH\n",
    "aspect = n_rows / n_cols\n",
    "fig = plt.figure(1, figsize=(total_width, aspect * total_width), constrained_layout=False)\n",
    "\n",
    "gs = fig.add_gridspec(2*n_rows, 2*n_cols, wspace=0.05, hspace=-0.3, width_ratios=[1, 1, 1, 1, 0.73, 0.73])\n",
    "row = 0\n",
    "title_offset = -0.1\n",
    "inset_label_offset = -0.2\n",
    "names = ['Reference', 'Ours']\n",
    "for scene_name, crop, exposure, curr_insets in zip(scenes, crops, exposures, insets):\n",
    "    col = 0\n",
    "    ax = fig.add_subplot(gs[row:row+2, 2*col:2*col+2])\n",
    "    ref_img = read_img(join(fig_dir, scene_name, 'ref.exr'), exposure=exposure)\n",
    "    ax.imshow(ref_img, interpolation='none', extent=[0,1,0,1])\n",
    "    ax.set_xlim(crop[0], crop[1])\n",
    "    ax.set_ylim(crop[2], crop[3])\n",
    "    disable_ticks(ax)\n",
    "    if row == 0:\n",
    "        txt = ax.set_title(names[col], fontsize=fontsize, va='top', y=title_offset)\n",
    "    col += 1\n",
    "    \n",
    "    ax = fig.add_subplot(gs[row:row+2, 2*col:2*col+2])\n",
    "    img = read_img(join(fig_dir, scene_name, f'{config.name}.exr'), exposure=exposure)\n",
    "    h_orig = img.shape[0]\n",
    "    ax.imshow(img, interpolation='none', extent=[0,1,0,1])\n",
    "    ax.set_xlim(crop[0], crop[1])\n",
    "    ax.set_ylim(crop[2], crop[3])\n",
    "    disable_ticks(ax)\n",
    "    if row == 0:\n",
    "        txt = ax.set_title(names[col], fontsize=fontsize, va='top', y=title_offset)\n",
    "    col += 1\n",
    "\n",
    "    for inset in curr_insets:\n",
    "        rect = patches.Rectangle((inset[0], inset[1]), inset[2], inset[2], linewidth=0.5, edgecolor='r', facecolor='none')\n",
    "        ax.add_patch(rect)\n",
    "\n",
    "    # # ax.arrow(0.7, 0.52, 0.02, -0.09, head_width=0.02, \n",
    "    # #         length_includes_head=True, facecolor='r', edgecolor='r')\n",
    "    # # ax.arrow(0.4, 0.6, -0.02, -0.09, head_width=0.02, \n",
    "    # #         length_includes_head=True, facecolor='r', edgecolor='r')\n",
    "    for r, inset in enumerate(curr_insets):\n",
    "        ax = fig.add_subplot(gs[r, 4])\n",
    "        i, j = (int(ref_img.shape[0] * (1-inset[1])), int(ref_img.shape[1] * inset[0]))\n",
    "        h, w = ref_img.shape[:2]\n",
    "        ref_crop = ref_img[(i - int(inset[2] * h)):i, j:(j + int(inset[2] * w))]\n",
    "        ax.imshow(ref_crop, interpolation='none')\n",
    "        disable_ticks(ax)\n",
    "        if r == 1:\n",
    "            txt = ax.set_title(\"Ref.\", fontsize=fontsize, va='top', y=inset_label_offset)\n",
    "\n",
    "        ax = fig.add_subplot(gs[r, 5])\n",
    "        img_crop = img[(i - int(inset[2] * h)):i, j:(j + int(inset[2] * w))]\n",
    "        ax.imshow(img_crop, interpolation='none')\n",
    "        disable_ticks(ax)\n",
    "        if r == 1:\n",
    "            txt = ax.set_title(\"Ours\", fontsize=fontsize, va='top', y=inset_label_offset)\n",
    "\n",
    "plt.margins(0, 0)\n",
    "# save_fig(fig_name)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.4 ('mi')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "c8cc192903caa17681aa39d71202092ac11a526d37a1c4ad2948f13605924304"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
